package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.DbUtil;
import vo.ListUser;
import dao.ListUserDao;

public class ListUserServlet extends HttpServlet {
	//ListUserDao listUserDao=new ListUserDao();
	DbUtil dbUtil=new DbUtil();

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		try{
			Connection con=null;
			ListUser resultlistUser=null;
			con=dbUtil.getCon();
			String sql="select state,id,name,telephone,mail,date from consumer";
			Statement ptmt=con.createStatement();
			ResultSet rs=ptmt.executeQuery(sql);
			List<ListUser> listuser=new ArrayList<ListUser>();
			while(rs.next()){
				resultlistUser=new ListUser();
				resultlistUser.setState(rs.getString(1));
				resultlistUser.setId(rs.getString(2));
				resultlistUser.setName(rs.getString(3));
				resultlistUser.setTelephone(rs.getString(4));
				resultlistUser.setMail(rs.getString(5));
				resultlistUser.setDate(rs.getString(6));
				listuser.add(resultlistUser);
			}
			request.setAttribute("listuser", listuser);
			ptmt.close();
			rs.close();
			con.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		request.getRequestDispatcher("listUser.jsp").forward(request,response);
		
	}

	 
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
